using System.Collections;

namespace PsVcs
{
    public class Conference
    {
        private string _code;
        private double _fees;
        private readonly IList _sessions = new ArrayList();
        private readonly IList _attendees = new ArrayList();

        private Conference()
        {
            
        }

        public Conference(string pConCode, double pConFees):this()
        {
            Fees = pConFees;
            Code = pConCode;
        }

        public string Code
        {
            get { return _code; }
            set { _code = value; }
        }

        public double Fees
        {
            get { return _fees; }
            set { _fees = value; }
        }

        public IList Sessions
        {
            get { return _sessions; }
        }

        public IList Attendees
        {
            get { return _attendees; }
        }

        public void Add(Session pSession)
        {
            if (null == pSession) throw new PsVcsException(PsVcsException.ConferenceNullSessionAdded);
            if (Exists(pSession)) throw new PsVcsException(PsVcsException.ConferenceDuplicateSessionAdded);
            Sessions.Add(pSession);
        }

        private bool Exists(Session pSession)
        {
            return Sessions.Contains(pSession);
        }

        public void Register(Attendee pAttendee)
        {
            if (null == pAttendee) throw new PsVcsException(PsVcsException.ConferenceNullAttendeeRegistered);
            if (Exists(pAttendee)) throw new PsVcsException(PsVcsException.ConferenceDuplicateAttendeeRegistered);
            Attendees.Add(pAttendee);
            pAttendee.Fees += Fees;
        }

        public bool Exists(Attendee pAttendee)
        {
            return Attendees.Contains(pAttendee);
        }

        public override bool Equals(object rhs)
        {
            Conference oConf = (Conference) rhs;
            return (Code.Equals(oConf.Code));
        }

        public override int GetHashCode()
        {
            return Code.GetHashCode();
        }

    }
}
